package com.sskj.uboex.ui.fragment;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.bean.RechargeListBean;
import com.sskj.uboex.R;
import com.sskj.uboex.presenter.RechargeAndWithdrawRecordFragmentPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Flowable;

@Route(path = RConfig.APP_FRAGMENT_RECHARGE_AND_WITHDRAW)//充提币记录
public class RechargeAndWithdrawRecordFragment extends BaseFragment<RechargeAndWithdrawRecordFragmentPresenter> {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    @Autowired
    String type;
    @Autowired
    String code;


    @Override
    protected int getLayoutId() {
        return R.layout.app_fragment_recharge_and_withdraw_record;
    }

    @Override
    public RechargeAndWithdrawRecordFragmentPresenter getPresenter() {
        return new RechargeAndWithdrawRecordFragmentPresenter();
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getActivity())
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 10))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.app_f2f))
        );
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.app_recy_item_recharge_and_withdraw_record, new SlimInjector<RechargeListBean>() {
            @Override
            public void onInject(RechargeListBean data, IViewInjector injector, List payloads) {

                injector
                        .text(R.id.tvAddress, data.getWalletAddr())
                        .text(R.id.tvNum, data.getUsdFee())
                        .text(R.id.tvAddressTitle, type.equals("1") ? "充币地址" : "提币地址")
                        .text(R.id.tvNumTitle, type.equals("1") ? "充币数量" : "提币数量")
                        .text(R.id.tvTime, data.getCreateTime())
                        .text(R.id.btStatus, data.getInspectStatus() == 3 ? App.INSTANCE.getString(com.sskj.mine.R.string.mineAssetRecordFragment8) : data.getInspectStatus() == 2 ? App.INSTANCE.getString(com.sskj.mine.R.string.mineAssetRecordFragment9) : data.getInspectStatus() == 1 ? App.INSTANCE.getString(com.sskj.mine.R.string.mineAssetRecordFragment10) : App.INSTANCE.getString(com.sskj.mine.R.string.mineAssetRecordFragment8));


            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<RechargeListBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<RechargeListBean>)
                page -> mPresenter.getAssetRecord(page, 20, type, code), 20);
        MVCCoolHelper<List<RechargeListBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

}
